import { useEffect, useState } from "react"
import { addSignInRecord } from "@/api/user"
import { message } from "antd"

/**
 * 添加用户签到记录
 */
const useAddUserSignInRecord = () => {
  const [loading, setLoading] = useState<boolean>(false)

  const doFetch = async () => {
    try {
      setLoading(true)
      await addSignInRecord()
    } catch (e) {
      if (e instanceof Error) {
        message.error("添加刷题签到记录失败，" + e.message)
      }
    } finally {
      setLoading(false)
    }
  }

  useEffect(() => {
    doFetch()
  }, [])

  return { loading }
}

export default useAddUserSignInRecord
